package com.aierjun.idcardorclib;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.ByteArrayOutputStream;

/**
 * Created by Ani_aierJun on 2017/9/28.
 */

public class CameraParcelable implements Parcelable {
    private long id;
    private String name;
    private String sex;
    private String familyName;
    private String birthday;
    private String address;
    private String idNumber;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getFamilyName() {
        return familyName;
    }

    public void setFamilyName(String familyName) {
        this.familyName = familyName;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public static Creator<CameraParcelable> getCREATOR() {
        return CREATOR;
    }

    protected CameraParcelable(Parcel in) {
    }

    public CameraParcelable() {
    }

    public static final Creator<CameraParcelable> CREATOR = new Creator<CameraParcelable>() {
        @Override
        public CameraParcelable createFromParcel(Parcel in) {
            CameraParcelable cameraParcelable = new CameraParcelable();
            cameraParcelable.id = in.readLong();
            cameraParcelable.name = in.readString();
            cameraParcelable.sex = in.readString();
            cameraParcelable.familyName = in.readString();
            cameraParcelable.birthday = in.readString();
            cameraParcelable.address = in.readString();
            cameraParcelable.idNumber = in.readString();
            return cameraParcelable;
        }

        @Override
        public CameraParcelable[] newArray(int size) {
            return new CameraParcelable[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeLong(id);
        parcel.writeString(name);
        parcel.writeString(sex);
        parcel.writeString(familyName);
        parcel.writeString(birthday);
        parcel.writeString(address);
        parcel.writeString(idNumber);
    }

    public static Bitmap getBitmap(byte[] data) {
        return BitmapFactory.decodeByteArray(data, 0, data.length);
    }

    public static byte[] getBytes(Bitmap bitmap) {
        ByteArrayOutputStream baops = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 0, baops);
        return baops.toByteArray();
    }
}
